package com.ruoyi.common.file.obs;

import com.obs.services.ObsClient;
import com.ruoyi.common.file.core.FileProperties;
import com.ruoyi.common.file.core.FileTemplate;
import lombok.RequiredArgsConstructor;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;

/**
 * ClassName：ObsAutoConfiguration
 * Package：com.ruoyi.common.file.obs
 * Description：华为云-对象存储服务-OBS自动配置类
 *
 * @Author：fpy
 * @Create：2025/5/7 - 10:01
 * @Version：v1.0
 */
@RequiredArgsConstructor
@EnableConfigurationProperties({ObsProperties.class})
public class ObsAutoConfiguration {

    private final FileProperties fileProperties;

    private final ObsProperties obsProperties;

    @Bean(name = "fileTemplate")
    @ConditionalOnMissingBean(FileTemplate.class)
    @ConditionalOnProperty(name ="file.type",havingValue = "obs")
    public FileTemplate obsTemplate() {
        ObsClient obsClient = new ObsClient(obsProperties.getAccessKey(), obsProperties.getSecurityKey(), obsProperties.getEndpoint());
        return new ObsTemplate(fileProperties, obsClient);
    }

}
